<template>
  <div>
    <van-tabbar route>
      <van-tabbar-item replace to="/home" icon="home-o">首页</van-tabbar-item>
      <van-tabbar-item replace to="/fenlei" icon="search">分类</van-tabbar-item>
      <van-tabbar-item replace to="/zhidemai" icon="hot-sale-o"
        >值得买</van-tabbar-item
      >
      <van-tabbar-item  icon="shopping-cart-o" @click="fun1"
         >购物车</van-tabbar-item
      >
      <van-tabbar-item replace icon="manager-o" @click="fun"
        >我的</van-tabbar-item
      >
    </van-tabbar>
  </div>
</template>

<script>
import axios from "../../request/service.js";
export default {
  data() {
    return {
      active: 0,
    };
  },
  methods: {
    fun() {
      let str = sessionStorage.getItem("phone");
      console.log(str);
      if (str != null) {
        this.$router.push("/personal");
      } else {
        this.$router.push("/my");
      }
    },
    fun1() {
            if (sessionStorage.getItem("token")) {
                this.$router.push("/cart");
                console.log(this.token);
            } else {
                this.$router.push("/my");

                console.log(sessionStorage.getItem("token"));
            }
            axios({
                url: `http://118.178.238.19:3001/api/cart/add`,
                method: "POST",
                data: {
                    token: sessionStorage.getItem("token"),
                    userid: sessionStorage.getItem("userid"),
                    proid: this.$route.query.id,
                },
            }).then((res) => {
                console.log(res);
            });

        },
  },
};
</script>

<style>
.div {
  z-index: 10;
}
</style>